﻿//////////////////////////////////////////////////////////////////////////////////////////////////////
//Name: Bartosz
//FullName: Adamczewski
//Project: InternalClasses
//Component: InternalClasses
//StartDate: 2009-08-17 19:29:04
//EndDate: 2009-08-17 19:29:04
//Description: The implementation of InternalClasses component.
//Rights:  Copyright (c) Bartosz Adamczewski
/////////////////////////////////////////////////////////////////////////////////////////////////////

#region imports.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection.Emit;
using System.Reflection;
using InternalClasses.Dynamic;

#endregion

namespace InternalClasses.Context.Actions
{
    /// <summary>
    /// The Is Not Null Action.
    /// </summary>
    public class IsNotNullAction : MethodInjectionAction
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="IsNotNullAction"/> class.
        /// </summary>
        public IsNotNullAction() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="IsNotNullAction"/> class.
        /// </summary>
        /// <param name="validateParameter">validateParameter.</param>
        public IsNotNullAction(params bool[] validateParameter) 
        {
            base.Method = typeof(IsNotNullAction).GetMethod("Validate");
            base.InjectionType = InternalClasses.Dynamic.InjectionType.BeforeSource;
            base.Parameters = new object[validateParameter.Length];

            for (int i = 0; i < Parameters.Length; i++)
            {
                Parameters[i] = validateParameter[i];
            }
        }

        /// <summary>
        /// the Validate.
        /// </summary>
        /// <param name="methodData">methodData.</param>
        /// <param name="metaData">metaData.</param>
        public void Validate(object[] methodData, object[] metaData)
        {
            for (int i = 0; i < metaData.Length; i++)
            {
                if ((bool)metaData[i])
                {
                    if (methodData[i] == null)
                    {
                        throw new Validation.ValidatorException("Parameter " + i + " is null");
                    }
                }
            }
        }
    }
}
